package com.nintendo.utils;

import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.zookeeper.data.Stat;
import org.junit.Test;

public class CuratorConfig {
    private static String host = "192.168.108.132:2181";// zookeeper地址
    private static Integer connectionTimeoutMs = 30*1000;//连接超时时间
    private static Integer sessionTimeoutMs = 3*1000;//会话超时时间
    private static Integer sleepMsBetweenRetry = 2*1000;// 休眠时间
    private static Integer maxRetries = 3; // 最大重试次数
    private static String namespace = "itzixi-im"; // 命名空间
    private static CuratorFramework client;
    static {
        RetryPolicy retryPolicy = new ExponentialBackoffRetry(sleepMsBetweenRetry,maxRetries);
        client = CuratorFrameworkFactory.builder()
        .connectString(host).connectionTimeoutMs(connectionTimeoutMs)
                .sessionTimeoutMs(sessionTimeoutMs)
                .retryPolicy(retryPolicy).namespace( namespace)
                .build();
        client.start();

    }
    public static CuratorFramework getClient(){
        return client;
    }
    @Test
    public void test() throws Exception {
        CuratorFramework client = CuratorConfig.getClient();
        String path = "/abc";
        Stat stat = client.checkExists().forPath(path);
        System.out.println(stat);
    }
}
